package cn.bdqn.service.impl;

import cn.bdqn.domain.Charge;
import cn.bdqn.mapper.ChargeMapper;
import cn.bdqn.service.ChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 收费的业务实现
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ChargeServiceImpl implements ChargeService {
    @Autowired
    private ChargeMapper chargeMapper;

    /**
     * 根据病人信息id查询收费信息
     * @param menberId
     * @return
     */
    @Override
    public Charge queryByMenberId(Integer menberId) {
        return chargeMapper.selectByMenberId(menberId);
    }

    /**
     * 根据收费id修改收费单状态为已支付
     * @param menberId
     */
    @Override
    @Transactional( rollbackFor =Exception.class ,propagation = Propagation.REQUIRES_NEW)
    public int updateByMenberId(Integer menberId) {
       return chargeMapper.updateByMenberId(menberId);
    }

    /**
     * 添加收费信息
     * @param charge
     * @return
     */
    @Override
    @Transactional( rollbackFor =Exception.class ,propagation = Propagation.REQUIRES_NEW)
    public int addCharge(Charge charge) {
        return chargeMapper.insert(charge);
    }

    /**
     * 根据menber_id查询收费单pay_status状态为0的数据的数量
     * @param menberId
     * @return
     */
    @Override
    public int queryVerifyById(int menberId) {
        return chargeMapper.selectVerifyById(menberId);
    }

    /**
     * 查询全部收费信息
     * @return
     */
    @Override
    public List<Charge> queryAll() {
        return chargeMapper.selectAll();
    }
}
